package tushare

import (
	"tushare/model/mysql"
)

type BackFive struct {
	Id         int64   `json:"id"`
	TsCode     string  `json:"ts_code"`
	Name       string  `json:"name"`
	TradeDate  string  `json:"trade_date"`
	FiveAmount float64 `json:"five_amount"`
	Close      float64 `json:"close"`
	Vol        float64 `json:"vol"`
	Amount     float64 `json:"amount"`
}

func BackFiveCreate(bf BackFive) {
	mysql.DB.Table("tushare_back_five").Create(&bf)
}

func BackFiveList(page, pageSize int64, tradeDate string) []BackFive {
	page = page
	pageSize = pageSize
	offset := (page - 1) * pageSize

	bf := []BackFive{}
	mysql.DB.Table("tushare_back_five").Where("trade_date = ?", tradeDate).Order("amount DESC").Limit(pageSize).Offset(offset).Scan(&bf)
	return bf
}

func BackFiveCount(tradeDate string) int64 {
	var count int64
	mysql.DB.Table("tushare_back_five").Where("trade_date = ?", tradeDate).Count(&count)
	return count
}
